﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using GoShopping.BLL.SysInfo;
using System.Collections.Generic;

public partial class RemarkCenter : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SetControlCommon.GetDDLType(ddlType);
            GetRemarkList(ddlType.SelectedValue);
        }
    }

    public void GetRemarkList(string filter)
    {
        RemarkPrdctBean rpb = new RemarkPrdctBean();
        if (filter == "-1")
        {
            lvRemarkCenter.DataSource = null;
            lvRemarkCenter.DataBind();
        }
        else
        {
            lvRemarkCenter.DataSource = rpb.GetRemarkProductByType(Convert.ToInt16(filter));
            lvRemarkCenter.DataBind();
        }
    }
    protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
    {
        GetRemarkByPrdt();
        GetRemarkList(ddlType.SelectedValue);
    }

    private void GetRemarkByPrdt()
    {
        ddlPrdt.Items.Clear();
        GoShopping.BLL.ProductBean pb = new GoShopping.BLL.ProductBean();
        ddlPrdt.DataTextField = "Name";
        ddlPrdt.DataValueField = "ID";
        ListItem li = new ListItem("--请选择--", "-1");
        ddlPrdt.Items.Add(li);
        IList<GoShopping.Model.Product> prdtList = pb.GetProductList(" AND producttypeid=" + ddlType.SelectedValue);
        foreach (GoShopping.Model.Product prdt in prdtList)
        {
            ListItem li1 = new ListItem(prdt.Name, prdt.ID.ToString());
            ddlPrdt.Items.Add(li1);
        }
    }
    protected void lvRemarkCenter_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
    {
        ((DataPager)(this.lvRemarkCenter.FindControl("DataPager1"))).SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
        GetRemarkList(ddlType.SelectedValue);
    }
    protected void lvRemarkCenter_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        if (ListViewItemType.DataItem == e.Item.ItemType)
        {
            HyperLink prdt = e.Item.FindControl("lblPrdt") as HyperLink;
            ListView lvi = e.Item.FindControl("lvRemarkCenter1") as ListView;
            GoShopping.BLL.SysInfo.RemarkPrdctBean rpb = new RemarkPrdctBean();
            lvi.DataSource = rpb.GetRemarkByProduct(prdt.Text);
            lvi.DataBind();
        }
    }
    protected void ddlPrdt_SelectedIndexChanged(object sender, EventArgs e)
    {
        RemarkPrdctBean rpb = new RemarkPrdctBean();
        if (ddlPrdt.SelectedValue != "-1")
        {
            List<int> prdtId = new List<int>();
            prdtId.Add(Convert.ToInt32(ddlPrdt.SelectedValue));
            lvRemarkCenter.DataSource = prdtId;
            lvRemarkCenter.DataBind();
            return;
        }
        GetRemarkList(ddlType.SelectedValue);
    }
}
